home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-18 | 4.5 KB | 201 lines | [TEXT/MMCC] |
- // If the interfaces aren't included yet, do the standard includes. Otherwise, precompiled headers
- // have been loaded already, thank you very much
- #ifndef __TYPES__
- #include <Types.h>
- #include <AppleEvents.h>
- #include <Desk.h>
- #include <Dialogs.h>
- #include <Editions.h>
- #include <Events.h>
- #include <Menus.h>
- #include <SegLoad.h>
- #include <TextUtils.h>
- #include <ToolUtils.h>
- #include <Windows.h>
- #endif
-
- #include "eventHandler.h"
- #include "fileMenuRoutines.h"
- #include "menuDispatch.h"
- #include "WindowExtensions.h"
-
- /* Globals */
-
- extern Boolean gDone; // Set to true if user selects Quit
- extern WindowRef gRecordingFloater; // Reference to recording floating window
- extern WindowRef gToolsFloater; // Reference to tools floating window
- extern ActivateHandlerUPP gActivateEventHandler;
-
- // a test routine
- void TestManualModal(void);
-
-
- void DoMenuCommand(long menuChoice)
- {
- long menuID;
- long menuItem;
- short daRef;
- Str255 daName;
- Boolean editResult;
-
- menuID = (menuChoice & 0xFFFF0000) >> 16;
- menuItem = menuChoice & 0x0000FFFF;
-
- switch (menuID) {
- case rAppleMenuID: if (menuItem == kAboutItem)
- DoAbout();
- else {
- GetItem(GetMHandle(rAppleMenuID), (short) menuItem, daName);
- daRef = OpenDeskAcc(daName);
- }
- break;
- case rFileMenuID: HandleFileMenuItems((short) menuItem);
- break;
- case rEditMenuID: editResult = SystemEdit((short) (menuItem - 1));
- break;
- case rFloatersMenuID: HandlerFloaterMenuItems((short) menuItem);
- break;
-
- // for testing...
- case 132: TestManualModal();
- break;
- }
- HiliteMenu(0);
- }
-
- void DoAbout()
- {
- short alertResult;
-
- DeactivateFloatersAndFirstDocumentWindow();
- alertResult = Alert(256, nil);
- ActivateFloatersAndFirstDocumentWindow();
- }
-
- void HandleFileMenuItems(short theItem)
- {
- switch (theItem) {
- case kNewItem: CreateNewDocumentWindow();
- break;
- case kOpenItem: GetFileToOpen();
- break;
- case kCloseItem: CloseFirstDocumentWindow();
- break;
- case kFindItem: ShowFindDialog();
- break;
- case kQuitItem: gDone = true;
- break;
- }
- }
-
- void HandlerFloaterMenuItems(short theItem)
- {
- Boolean floaterVisible;
- WindowRef floaterPicked;
-
- switch (theItem) {
- case kRecordingItem: floaterPicked = gRecordingFloater;
- break;
- case kToolsItem: floaterPicked = gToolsFloater;
- break;
- }
-
- floaterVisible = IsWindowVisible(floaterPicked);
- if (floaterVisible == false)
- ShowReferencedWindow(floaterPicked);
- else
- HideReferencedWindow(floaterPicked);
- CheckItem(GetMHandle(rFloatersMenuID), theItem, !floaterVisible);
- }
-
- void CreateNewDocumentWindow()
- {
- WindowRef newDocumentWindow;
- OSErr createWindowError;
-
- ValidateWindowList();
- createWindowError = GetNewWindowReference(&newDocumentWindow, 128,
- (WindowRef) -1, gActivateEventHandler);
- if (createWindowError == noErr) {
- ShowReferencedWindow(newDocumentWindow);
- EnableItem(GetMHandle(rFileMenuID), kCloseItem);
- }
- }
-
- void CloseFirstDocumentWindow()
- {
- WindowRef firstDocumentWindow;
-
- ValidateWindowList();
- firstDocumentWindow = FrontNonFloatingWindow();
- if (firstDocumentWindow != nil)
- DisposeWindowReference(firstDocumentWindow);
- if (FrontNonFloatingWindow() == nil)
- DisableItem(GetMHandle(rFileMenuID), kCloseItem);
- }
-
- void ShowFindDialog()
- {
- DialogRef findDialog;
-
- DeactivateFloatersAndFirstDocumentWindow();
- findDialog = GetNewDialog(257, nil, (WindowRef)-1);
- DisableItem(GetMHandle(rAppleMenuID), 0);
- DisableItem(GetMHandle(rFileMenuID), 0);
- DrawMenuBar();
- }
-
- void DisposeFindDialog()
- {
- DialogRef findDialog;
-
- findDialog = (DialogRef)FrontWindow();
- DisposeDialog(findDialog);
- ActivateFloatersAndFirstDocumentWindow();
- EnableItem(GetMHandle(rAppleMenuID), 0);
- EnableItem(GetMHandle(rFileMenuID), 0);
- DrawMenuBar();
- }
-
- void TestManualModal(void)
- {
- Rect theRect;
- OSErr error;
- WindowAttributes attributes;
- WindowRef wind;
- ControlHandle cHandle;
-
- // Put up a movable modal
- attributes = kHasModalBorderMask + kHasDocumentTitlebarMask;
- SetRect(&theRect, 200, 100, 400, 250);
-
- // create the window invisibly
- error = NewWindowReference(&wind, &theRect, "\pTesty Mambo", false,
- attributes, (WindowRef) -1, (long)'DAVE', nil);
-
- if(wind == nil)
- return;
-
- // Set its kind
- //SetWindowKind(wind, dialogKind);
-
- // Add a button
- SetRect(&theRect, 20, 20, 80, 40);
- cHandle = NewControl(wind, &theRect, "\pPress", true, 0, 0, 1, 0, 'DAVE');
-
- // Show window
- DeactivateFloatersAndFirstDocumentWindow();
- ShowReferencedWindow(wind);
- }
-
-
-
-
-
-
-
-
-
-
-
-